package com.itheima.user.controller;

import com.itheima.common.pojo.Result;
import com.itheima.user.dto.LoginDto;
import com.itheima.user.service.ApUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/loginUser")
public class LoginController {

    @Autowired
    private ApUserService apUserService;

    /**
     * 登录
     *      1.游客
     *      2.会员
     */
    @PostMapping(value = "/login")
    public Result login(@RequestBody LoginDto dto){
        String token = apUserService.login(dto);
        if (token == null){
            return Result.errorMessage("密码错误");
        }
        return Result.ok(token);
    }

}
